package com.strongdigit.ioc.resource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;

import java.io.IOException;

public class MoocResource implements ApplicationContextAware {

    private ApplicationContext actx;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        this.actx = applicationContext;
    }

    public void loadResource() throws IOException {

        //Resource r = actx.getResource("classpath:config.txt");
        //Resource r = actx.getResource("file:/Users/tiansx/study/spring/spring/sample-ioc/src/main/resources/config.txt");
        Resource r = actx.getResource("url:http://car.bitauto.com/ruizhi");
        System.out.println(r.getFilename());

        System.out.println(r.contentLength());
    }
}
